/*
 * @Description:
 * @Author: Zzt
 * @Date: 2022-11-10 16:49:18
 * @LastEditTime: 2022-12-19 17:49:56
 */
import { createContext, useReducer, useEffect, useContext } from 'react';
import { SET_ARCHIVES, SET_TERM, SET_SECRET } from '../constants';
import { BasicStatisticsReducer } from '../reducers/BasicStatisticsReducer';
import { volumeByFonds, electronicFileTotal, secretTotal } from '@/api/statistics/basicStatistics';
const initialState = {
  archivesList: [],
  termList: [],
  secretList: []
};
const BasicStatistics = createContext();
const BasicStatisticsProvider = (props) => {
  const [state, dispatch] = useReducer(BasicStatisticsReducer, initialState);
  const actions = {
    setArchivesList(data) {
      volumeByFonds(data).then((res) => {
        const { data } = res;
        dispatch({ type: SET_ARCHIVES, data });
      });
    },
    setTermList(data) {
      electronicFileTotal(data).then((res) => {
        const { data } = res;
        dispatch({ type: SET_TERM, data });
      });
    },
    setSecretList(data) {
      secretTotal(data).then((res) => {
        const { data } = res;
        dispatch({ type: SET_SECRET, data });
      });
    }
  };
  useEffect(() => {}, []);
  return (
    <BasicStatistics.Provider value={{ ...state, ...actions }}>
      {props.children}
    </BasicStatistics.Provider>
  );
};
export const useBasicStatistics = () => {
  return useContext(BasicStatistics);
};
export { BasicStatistics, BasicStatisticsProvider };
